package com.joven.core;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author joven_wong
 * 2021/10/13 10:18
 */
public class Java8Test1 {
    public static void main(String[] args) {

        List<MoneyOne> list = new ArrayList<>();
        list.add(new MoneyOne("CNY",1));
        list.add(new MoneyOne("MY",9));
        list.add(new MoneyOne("OY",5));

//        List<Integer> l2 = list.stream().map(MoneyOne::getAmt).collect(Collectors.toList());
//        l2.forEach(System.out::println);
        Integer sum = list.stream().map(MoneyOne::getAmt).reduce((x,y)->x += y).orElse(0);
        System.out.println(sum);

        List<BigDecimal> list2= new ArrayList<>();
        list2.add(new BigDecimal("10")); list2.add(new BigDecimal("15")); list2.add(new BigDecimal("5"));
        BigDecimal sum1= list2.stream().reduce(BigDecimal::add).orElse(new BigDecimal("0"));
        System.out.println(sum1);
    }

    static class MoneyOne {
        private int amt;

        public String getBz() {
            return bz;
        }

        public void setBz(String bz) {
            this.bz = bz;
        }

        private String bz;

        public MoneyOne(String bz,int amt) {
            this.amt = amt;
            this.bz = bz;
        }

        public int getAmt() {
            return amt;
        }

        public void setAmt(int amt) {
            this.amt = amt;
        }
    }
}
